# Git命令执行助手 - 查找Git并执行推送

Write-Host "🔍 正在查找Git安装位置..." -ForegroundColor Yellow

# 常见Git安装路径
$gitPaths = @(
    "C:\Program Files\Git\bin\git.exe",
    "C:\Program Files\Git\cmd\git.exe", 
    "C:\Program Files (x86)\Git\bin\git.exe",
    "C:\Users\$env:USERNAME\AppData\Local\Programs\Git\bin\git.exe"
)

$gitFound = $false
$gitPath = ""

foreach ($path in $gitPaths) {
    if (Test-Path $path) {
        Write-Host "✅ 找到Git: $path" -ForegroundColor Green
        $gitPath = $path
        $gitFound = $true
        break
    }
}

if (-not $gitFound) {
    Write-Host "❌ 未找到Git安装" -ForegroundColor Red
    Write-Host "📥 请确保已安装Git: https://git-scm.com/download/win" -ForegroundColor Yellow
    exit 1
}

# 进入项目目录
Set-Location "C:\Users\Administrator\Documents\trae_projects\lt00001\magazine"
Write-Host "📁 当前目录: $(Get-Location)" -ForegroundColor Yellow

# 执行Git命令
Write-Host "📊 检查Git状态..." -ForegroundColor Yellow
& $gitPath status

Write-Host "📝 添加所有PWA相关文件..." -ForegroundColor Yellow
& $gitPath add .

Write-Host "💾 提交更改..." -ForegroundColor Yellow
$commitMessage = @"
feat: 添加完整的PWA功能实现

- 添加Web App Manifest配置
- 实现Service Worker缓存策略
- 添加PWA安装提示功能
- 优化移动端适配和响应式设计
- 添加离线功能和测试工具
- 更新主题模板支持PWA
"@

& $gitPath commit -m $commitMessage

Write-Host "🔄 推送到远程仓库..." -ForegroundColor Yellow
Write-Host "执行命令: & `"$gitPath`" push -u origin main" -ForegroundColor Cyan

& $gitPath push -u origin main

if ($LASTEXITCODE -eq 0) {
    Write-Host "✅ 推送成功！" -ForegroundColor Green
    Write-Host "🎉 PWA功能已上传到远程仓库" -ForegroundColor Green
    Write-Host "🔄 GitHub Actions将自动同步到Gitee（如果配置了）" -ForegroundColor Yellow
} else {
    Write-Host "❌ 推送失败" -ForegroundColor Red
    Write-Host "🔧 可能的原因：" -ForegroundColor Yellow
    Write-Host "   1. 远程仓库地址未配置" -ForegroundColor White
    Write-Host "   2. 需要身份验证" -ForegroundColor White
    Write-Host "   3. 分支名称不正确" -ForegroundColor White
    Write-Host "" -ForegroundColor White
    Write-Host "💡 解决方案：" -ForegroundColor Cyan
    Write-Host "   1. 配置远程仓库：" -ForegroundColor White
    Write-Host "      & `"$gitPath`" remote add origin https://gitee.com/你的用户名/magazine.git" -ForegroundColor Gray
    Write-Host "   2. 尝试推送到master分支：" -ForegroundColor White
    Write-Host "      & `"$gitPath`" push -u origin master" -ForegroundColor Gray
}

Write-Host "按任意键退出..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")